<!DOCTYPE html>
<html class="pixel-ratio-1"><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>茵曼商城</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="css/sm.min.css">
    <link rel="stylesheet" href="css/sm-extend.min.css">
    <link rel="stylesheet" href="css/inman.css">
    <script src="https://hm.baidu.com/hm.js?5ee51ef74fa865950bb9a2757fdb33ad"></script><script type="text/javascript" src="js/zepto.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/sm.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/sm-extend.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/functions.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/TouchSlide.1.1.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jweixin-1.0.0.js"></script>
    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?5ee51ef74fa865950bb9a2757fdb33ad";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</head>
<body>
<div class="page-group confirm-page">
    <div class="page page-current" id="page-1510723562638">
        <!--标题栏-->
        <header class="bar bar-nav">
            <a class="icon icon-left pull-left" href="javascript:history.back(-1);"></a>

            <h1 class="title">订单确认</h1>
        </header>

        <!--内容区-->
        <div class="content native-scroll">
            <!--收货地址-->
            <div class="box1">
                <!--现货-->
                <a href="http://m.inman.com.cn/index.php/User/address?goto=/index.php/Order/confirm?rec_id_list=6941919704150">
                    <h3>收货人 :信春廷&nbsp;&nbsp;15910288070</h3>

                    <p>北京北京市通州区土桥</p>
                </a>
                <input type="hidden" name="addr_id" value="286801">
            </div>
            <!--商品列表-->
            <div class="box2">
                <ul>
                    <li>
                        <a href="http://m.inman.com.cn/index.php/Goods/goodsdetail?goods_bn=1874121020">
                            <div class="w-20 g-img"><img src="http://img.inman.com.cn/uploads/image/20171012/1507781252215871.jpg"></div>
                            <div class="w-60">
                                <h4>茵曼冬装新款连帽加厚保暖中长款白鸭绒羽绒服女</h4>

                                <p>售价：￥799.00 /
                                    数量：1</p>

                                <p>颜色：军绿色 /
                                    尺码：S</p>
                            </div>
                            <div class="w-20 g-price">
                                <p><i>￥</i>799.00<br><span></span></p>
                            </div>
                            <div class="cb"></div>
                        </a>
                    </li>
                </ul>
            </div>
            <!--促销优惠-->
            <div class="box3">
                <div class="box3-1">
                    <a href="#" id="discount"><i class="ico">促</i>11.13-11.16跨时空对话（259-30/359-50/659-100/959-150/1259-200）</a>
                </div>
                <div class="box3-2">
                    <ul>
                        <li class="on" data-promotions_id="56daddf70184646ce9c938133b792bf9">
                            <span></span>

                            <div class="des">
                                <h4>11.13-11.16跨时空对话（259-30/359-50/659-100/959-150/1259-200）</h4>
                            </div>
                            <div class="cb"></div>
                        </li>
                        <li class=" zh" data-promotions_id="fbecf51175a582c246a9b715c2e46c10">
                            <span></span>

                            <div class="des">
                                <h4>组合优惠</h4>
                                <p>1.11.13-11.16跨时空对话（259-30/359-50/659-100/959-150/1259-200）</p>                                    </div>
                            <div class="cb"></div>
                        </li>
                        <li class="" data-promotions_id="3e60aef6769b61e5d6803dc54d1f4f71">
                            <span></span>

                            <div class="des">
                                <h4>无优惠</h4>
                            </div>
                            <div class="cb"></div>
                        </li>
                    </ul>
                </div>
            </div>
            <!--换购专区-->
            <div class="box4" style="display:none ">
                <a href="http://m.inman.com.cn/index.php/Order/changegoods?promotions_id=56daddf70184646ce9c938133b792bf9"><i class="ico">换</i>换购专区</a>
            </div>

            <!--优惠券-->
            <div class="box5" style="display:none ">
                <a href="http://m.inman.com.cn/index.php/Order/ordervouchers?promotion_id=56daddf70184646ce9c938133b792bf9"><i class="ico">券</i>优惠券
                    <i class="ico2">张可用</i>
                    <i name="discount" style="float:right;font-style:normal;padding-right:1.5rem;font-size:0.7rem"></i>
                </a>
            </div>
            <!--结算明细-->
            <div class="box6">
                <p>总计<span>￥<i style="font-style:normal" name="totalprice">799.00</i></span>
                </p>

                <p>运费<span>￥<i style="font-style:normal" name="fareprice">0.00</i></span></p>
                <p>共优惠金额<span>￥<i style="font-style:normal" name="discountprice">100.00</i></span>
                </p>
            </div>
        </div>

        <!--提交订单-->
        <div class="box7">
            <div class="box7-1">
                <h5>实付金额:</h5>

                <p>￥<span class="total">699.00</span></p>
            </div>
            <div class="box7-2"><a href="#" id="balance">提交订单</a></div>
            <div class="cb"></div>
        </div>

        <!--CoverWarp-->
        <div class="ying"></div>

        <!--选择支付方式-->
        <div class="box8">
            <h3>支付金额 <i>￥</i><span class="total">699.00</span>
            </h3>
            <h5>选择支付方式</h5>
            <ul>
                <li class="weixinpay on" data-payment="wxpay" style="display:none"><a href="#">
                    <p>微信支付</p>
                </a></li>
                <li class="alipay" data-payment="alipay"><a href="#">
                    <p>支付宝支付</p>
                </a></li>
            </ul>
            <a href="#" class="btn-pay">去支付</a>
            <a href="#" class="close-pay" data-order_id=""></a>
        </div>

        <input type="hidden" id="order_id">
    </div>
    <script>
        (function ($) {
            $.fn.slideDown = function (duration) {
                // get old position to restore it then
                var position = this.css('position');
                // show element if it is hidden (it is needed if display is none)
                this.show();
                // place it so it displays as usually but hidden
                this.css({
                    position: 'absolute',
                    visibility: 'hidden'
                });
                // get naturally height
                var height = this.height();
                // set initial css for animation
                this.css({
                    position: position,
                    visibility: 'visible',
                    overflow: 'hidden',
                    height: 0
                });
                // animate to gotten height
                this.animate({
                    height: height
                }, duration, 'ease');
            };

            $.fn.slideUp = function (duration) {
                // get old position to restore it then
                var position = this.css('position');
                // place it so it displays as usually but hidden
                this.css({
                    position: 'absolute'
                });
                // get naturally height
                var height = this.height();
                // set initial css for animation
                this.css({
                    position: position,
                    visibility: 'visible',
                    overflow: 'hidden'
                });

                // animate to gotten height
                var that = this;
                this.animate({
                    height: 0
                }, duration, 'ease', function () {
                    that.css({
                        display: 'none',
                        height: height
                    })
                });

            };
        })(Zepto);


        $(function () {
            var addrdata = [{"addr_id":286801,"name":"\u4fe1\u6625\u5ef7","addr":"\u571f\u6865","zip":"10000","tel":"","mobile":"15910288070","is_default":0,"country_name":"\u4e2d\u56fd\u5927\u9646","province_name":"\u5317\u4eac","city_name":"\u5317\u4eac\u5e02","district_name":"\u901a\u5dde\u533a","province_id":"110000","city_id":"110100","district_id":"110112"}];
            var address_id = localStorage['address_id'] || 0;
            if(addrdata){
                for (var n = 0; n < addrdata.length; n++) {
                    if (address_id == addrdata[n].addr_id) {
                        $("div.box1 a h3").html("收货人：" + addrdata[n].name + "&nbsp;&nbsp" + addrdata[n].mobile);
                        $("div.box1 a p").html(addrdata[n].province_name + addrdata[n].city_name + addrdata[n].district_name + addrdata[n].addr);
                        $("input[name='addr_id']").val(address_id);
                    }
                }
            }


            $('#discount').click(function () {
                if ($(this).is('.on')) {
                    $(this).removeClass('on');
                    $('.box3-2').slideUp(500);
                } else {
                    $(this).addClass('on');
                    $('.box3-2').slideDown(500);
                }
            });

            //点击支付方式
            $("a.btn-pay").click(function () {
                var final_amount = $("#order_id").attr("data-final_amount");
                var body = $("#order_id").attr("data-body");
                var payment = $("div.box8 ul li.on").attr("data-payment");
                var openid = "";
                var uri = "http://m.inman.com.cn/index.php/Order/wxpay";
                var order_id = $("#order_id").attr("data-order_id");
                var data = {openid: openid, order_id: order_id, final_amount: final_amount, body: body};
                if (payment == "alipay") {
                    uri = "http://m.inman.com.cn/index.php/Order/alipay";
                    data = {order_id: order_id, final_amount: final_amount, body: body}
                }
                var weixinjson;
                $.showIndicator();
                $.ajax({
                    cache: true,
                    type: "post",
                    url: uri,
                    data: data,
                    async: false,
                    success: function (json) {
                        json = eval('(' + json + ')');
                        if (json.errcode == '0') {
                            $.toast(json.errmsg);
                            return false;
                        }
                        $.hideIndicator();
                        if (payment == "wxpay") {
                            weixinjson = json.data;
                            function onBridgeReady() {
                                WeixinJSBridge.invoke(
                                    'getBrandWCPayRequest', weixinjson,
                                    function (res) {
                                        if (res.err_msg == "get_brand_wcpay_request:ok") {
                                            location.href = '/Order/payout?order_id=' + order_id;
                                        }
                                        // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                                    }
                                );
                            }

                            if (typeof WeixinJSBridge == "undefined") {
                                if (document.addEventListener) {
                                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                                } else if (document.attachEvent) {
                                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                                }
                            } else {
                                onBridgeReady();
                            }
                        } else {
                            location.href = json.url;
                        }
                    }
                })
            });

            //设置支付方式
            $('.box8 li').click(function () {
                $(this).addClass('on');
                $(this).siblings('li').removeClass('on');
                var payment = $(this).attr("data-payment");
                var uri = "http://m.inman.com.cn/index.php/Order/setpayment";
                var order_id = $("#order_id").attr("data-order_id");
                $.showIndicator();
                $.ajax({
                    cache: true,
                    type: "post",
                    url: uri,
                    data: {payment: payment, order_id: order_id},
                    async: false,
                    success: function (json) {
                        json = eval('(' + json + ')');
                        if (json.errcode == '0') {
                            $.toast(json.errmsg);
                            return false;
                        }
                        $.hideIndicator();
                    }
                })
            });

            $('.box3-2 ul li').click(function () {
                if ($(this).hasClass("on")) {
                    return false;
                }
                $(this).siblings('li').removeClass('on');
                $(this).addClass('on');
                var v = $(this).children('.des').children('h4').html();
                $('#discount').html('<i class="ico">促</i>' + v).removeClass('on');
                $('.box3-2').slideUp(500);
                var promotions_id = $(this).attr("data-promotions_id");
                var uri = "http://m.inman.com.cn/index.php/Order/ajaxchangePromotion";
                $.showIndicator();
                $.ajax({
                    cache: true,
                    type: "post",
                    url: uri,
                    data: {promotions_id: promotions_id},
                    async: false,
                    success: function (json) {
                        json = eval('(' + json + ')');
                        if (json.errcode == '0') {
                            $.toast(json.errmsg);
                            return false;
                        }
                        $.hideIndicator();
                        choosepromotions(json.data, promotions_id);
                    }
                })
            });

            $("#balance").click(function () {
                var addr_id = $("input[name='addr_id']").val();
                var uri = "http://m.inman.com.cn/index.php/Order/ajaxsubmit";
                var shop_id = "0";
                if(shop_id=="0" && !addr_id){
                    $.toast('请输入收货信息');
                    return false;
                }
                $.showIndicator();
                $.ajax({
                    cache: true,
                    type: "post",
                    url: uri,
                    data: {addr_id: addr_id, shop_id: shop_id},
                    async: false,
                    success: function (json) {
                        $.hideIndicator();
                        json = eval('(' + json + ')');
                        if (json.errcode != '1') {
                            $.toast(json.errmsg);
                            return false;
                        }
                        var orderdata = json.data;
                        var a = orderdata['order_id'];
                        var b = orderdata.order_id;
                        if (parseInt(shop_id) > 0) {
                            location.href = "/Order/orderdetails?order_id=" + orderdata.order_id;
                        } else {
                            openPay();
                            var arr = [];
                            var items = orderdata.items;
                            for (key in items) {
                                arr.push(items[key]['name']);
                            }
                            $("#order_id").attr("data-order_id", orderdata.order_id);
                            $("#order_id").attr("data-final_amount", orderdata.final_amount);
                            $("#order_id").attr("data-body", "茵曼商城" + arr.join(","));
                        }
                    }
                })
            })
        });

        //查看json的个数
        function JSONLength(obj) {
            var size = 0, key;
            for (key in obj) {
                if (obj[key]) size++;
            }
            return size;
        }
        ;


        function choosepromotions(promotionsdata, promotions_id) {
            $("span.total").text(Number(promotionsdata.final_amount).toFixed(2));
            $("i[name='totalprice']").html(Number(promotionsdata.total_cost).toFixed(2));
            $("i[name='fareprice']").html(Number(promotionsdata.postage).toFixed(2));
            $("i[name='discountprice']").html(Number((promotionsdata.pmt_order * 1 + promotionsdata.discount * 1)).toFixed(2));
            var size = 0, key;
            var arr = [];
            for (key in promotionsdata.coupons) {
                if (promotionsdata.coupons[key].enable == 1) {
                    size++;
                    arr.push(key);
                }
            }
            $("div.box5").hide();
            if (size > 0) {
                $("div.box5").show();
                $("div.box5 a").attr("href", '/Order/ordervouchers?promotion_id=' + promotions_id);
                $("i.ico2").html(size + "张可用");
                promotionsdata.discount > 0 ? "-" + $("i[name='discount']").val() : '';
            }
            $("div.box4").hide();
            var trade_goods = promotionsdata.trade_goods;
            $("p[name='changeprice']").hide();
            if (parseInt(promotionsdata.trade_fee) > 0) {
                $("p[name='changeprice']").show();
                $("p[name='changeprice'] span i").html(promotionsdata.trade_fee);
            }
            if (JSONLength(trade_goods) > 0) {
                $("div.box4").show();
                $("div.box4 a").attr("href", "/Order/changegoods?promotions_id=" + promotions_id);
            }
        }

        //打开支付方式
        function openPay() {
            var h = $('.box8').height();
            $('.box8').css({
                bottom: -h + 'px'
            });
            $('.ying').animate({
                display: 'block'
            }, 150);
            $('.box8').animate({
                bottom: '0'
            }, 300, 'ease');
        }
        ;

        //关闭支付方式
        $("a.close-pay").click(function () {
            var h = $('.box8').height();
            $('.ying').animate({
                display: 'none'
            }, 150);
            $('.box8').animate({
                bottom: -h + 'px'
            }, 300, 'ease');
            var order_id = $("#order_id").attr("data-order_id");
            location.href = "http://m.inman.com.cn/index.php/Order/orderdetails?order_id=" + order_id;
        });
        $.init();
    </script>
</div>


</body></html>